package appconfig

import (
	"fmt"
	viper "github.com/spf13/viper"
)

type Appconfig struct {
	Mysql struct {
		User     string
		Password string
		Host     string
		Port     int
		Database string
	}

	Redis struct {
		Addr     string
		Password string
		DB       int
	}
	SendSms struct {
		Account  string
		Password string
	}
}

var ConfigData Appconfig

func Init() {
	viper.SetConfigFile("../appconfig/config.yaml")

	err := viper.ReadInConfig()
	if err != nil {
		panic("读取配置文件失败")
	}

	err = viper.Unmarshal(&ConfigData)
	if err != nil {
		panic("解析配置文件失败")
	}

	fmt.Println(ConfigData)
}
